<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<%@ include file="/static/commom/head-import.jsp"%>
	<link type="text/css" rel="stylesheet" href="/static/commom/css/head-nav.css">
</head>
<body>
	<nav class="container-fluid navbar navbar-default">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand" title="首页">
					<img alt="Brand" src="/static/images/zhi_logo.jpg" style="width:30px;;height:28px;">
					<!-- <label class="glyphicon glyphicon-home"></label> -->
				</a>
			</div>
			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
				<!-- 左对齐 -->
				<ul class="nav navbar-nav">
					<li class="head-point active"><a>看吧</a></li>
					<li class="head-point" data-href="/say/classification/index"><a>说吧</a></li>
					<!-- <li class="dropdown">
			          	<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
			          	<ul class="dropdown-menu">
				            <li><a href="#">Action</a></li>
				            <li><a href="#">Another action</a></li>
				            <li><a href="#">Something else here</a></li>
				            <li role="separator" class="divider"></li>
				            <li><a href="#">Separated link</a></li>
				            <li role="separator" class="divider"></li>
				            <li><a href="#">One more separated link</a></li>
			          	</ul>
			        </li>
					<li class="dropdown">
			          	<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
			          	<ul class="dropdown-menu">
				            <li><a href="#">Action</a></li>
				            <li><a href="#">Another action</a></li>
				            <li><a href="#">Something else here</a></li>
				            <li role="separator" class="divider"></li>
				            <li><a href="#">Separated link</a></li>
				            <li role="separator" class="divider"></li>
				            <li><a href="#">One more separated link</a></li>
			          	</ul>
			        </li> -->
				</ul>
				<!-- 中间搜索框 -->
				<!-- <form class="navbar-form navbar-left">
					<div class="form-group">
						<input type="text" class="form-control" placeholder="搜索">
					</div>
					<button type="submit" class="btn btn-default">搜索</button>
				</form> -->
				<!-- 右对齐 -->
				<ul class="nav navbar-nav navbar-right">
					<li class="dropdown head-point" data-href="/security/account/index">
			          	<a href="#" id="personal" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
			          		个人中心 <span class="caret"></span></a>
			          	<ul class="dropdown-menu">
				            <li class="head-point show" data-href="/security/account/login" id="loginLi"><a>登录</a></li>
							<li class="head-point show" data-href="/security/account/register" id="registerLi"><a>注册</a></li>
							<li class="head-point hide" id="logoutLi"><a>退出</a></li>
			          	</ul>
			        </li>
					<!-- <li class="head-point" data-href="/security/account/index"><a id="personal">个人中心</a></li>
					<li class="head-point show" data-href="/security/account/login" id="loginLi"><a>登录</a></li>
					<li class="head-point show" data-href="/security/account/register" id="registerLi"><a>注册</a></li>
					<li class="head-point hide" id="logoutLi"><a>退出</a></li> -->
				</ul>
			</div>
		</div>
	</nav>
</body>

<script type="text/javascript">
	var say = say||{};
	say.account = say.account||{};
	say.account.head = say.account.head||{};
	
	//判断是否登录
	say.account.head.isLogin = function(){	
		var url = "/security/account/rest/getLoginInfo"
		$.ajax({
	       	type: 'GET',
	       	url: url,	//webservice
	       	dataType:'json',	
	       	success: function (result) {
		   		if(result && result.status){
					if(result.status==1 && result.content){	
						say.account.head.loginSucc(result.content.name);
					}
				}
	       	}
	   	});
	}

	//登录成功后的操作
	say.account.head.loginSucc = function(content){	
		$(".show").removeClass("show");
		$(".hide").removeClass("hide");
		$("#logoutLi").removeClass("show");
		
		$("#loginLi").addClass("hide");
		$("#registerLi").addClass("hide");
		$("#logoutLi").addClass("show");
		
		var userHtml = $("#personal").html();
		userHtml = userHtml.substring(userHtml.indexOf("-")+1,userHtml.lenght);
		$("#personal").html(content+" - "+userHtml);
	}

	//退出方法
	say.account.head.logout = function(){
		var url = "/security/account/logout";
		$.ajax({
	       	type: 'get',
	       	url: url,	//webservice
	       	data: {},
	       	dataType:'json',	
	       	success: function (result) {
		   		if(result && result.status){
					if(result.status==1){
						layer.msg(result.msg || "退出成功",{icon:1});
						say.account.head.logoutSucc();
					}else if(result.status==0){
						layer.msg(result.msg || "退出失败",{icon:1});
					}
				}
	       	},
	       	error: function(result){
	       		alert("未知错误");
	       	}
	   	});
	}

	//退出成功后的操作
	say.account.head.logoutSucc = function(){	
		$(".show").removeClass("show");
		$(".hide").removeClass("hide");
		
		$("#loginLi").addClass("show");
		$("#registerLi").addClass("show");
		$("#logoutLi").addClass("hide");
		
		var userHtml = $("#personal").html();
		userHtml = userHtml.substring(userHtml.indexOf("-")+1,userHtml.lenght);
		$("#personal").html(userHtml);

	}
	//导航条点击事件
	say.account.head.navClick = function(){
		$(".nav.navbar-nav li").removeClass("active");
		$(this).addClass("active");
		
		var dataUrl = $(this).attr("data-href");
		var newTitle = $(this).find("a").text();
		
		$("#indexDiv").load(dataUrl);
		base.setTitle(newTitle);
	}
	//清除全部active状态
	say.account.head.clearNavActive = function(){
		$(".nav.navbar-nav li").removeClass("active");
	}
	$(function(){
		say.account.head.isLogin();//判断是否登录
		/* 绑定事件 */
		$("#logoutLi").click(say.account.head.logout);	//登出事件
		
		$(document).on("click",".nav.navbar-nav li",say.account.head.navClick);	//导航条点击事件
	});
</script>

</html>